<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title></title>
</head>
<style type="text/css">
    body{
        text-align: center;
        overflow: hidden;
    }
    img{
        position: relative;
    }
</style>
<body>
<img id="img" src="images/P2009161881764593.jpg" alt=""/>

<button id="btn">get json</button>

<script type="text/javascript" src="../lib/jquery/jquery-1.11.1.js"></script>
<script type="text/javascript">
    var socket = io.connect('http://localhost');
    socket.on('news', function (data) {
        console.log(data);
        socket.emit('my other event', { my: 'data' });
    });

    $(function(){
        /**
         * $.delete 仿照$.get 扩展的delete请求
         * 必须传入的参数有：请求路径(url)、处理请求结果的回调函数(call)
         * 可选参数有：请求时传递的数据(data，为对象格式)、请求是否为异步请求的布尔值(async，默认为true)
         * 返回的数据默认是字符串处理
         * 传入参数的顺序为：url, [data], call, [async]
         */
        $.delete = function(){
            var len = arguments.length,
                    url = "",
                    data = {},
                    call = null,
                    async = true;
            console.log(len);
            if(len == 4){
                url = arguments[0];
                data = arguments[1];
                call = arguments[2];
                async = arguments[3];
            }else if(len == 3){
                if(typeof arguments[2] === "boolean"){
                    url = arguments[0];
                    call = arguments[1];
                    async = arguments[2];
                }else{
                    url = arguments[0];
                    data = arguments[1];
                    call = arguments[2];
                }
            }else if(len == 2){
                url = arguments[0];
                call = arguments[1];
            }
            $.ajax({
                type: "DELETE",
                url: url,
                data: data,
                success: call,
                async: async,
                dataType: "text"
            });
        };

        /**
         * $.put 仿照$.get 扩展的put请求
         * 必须传入的参数有：请求路径(url)、处理请求结果的回调函数(call)、请求时传递的数据(data，为对象格式)
         * 可选参数有：请求是否为异步请求的布尔值(async，默认为true)
         * 返回的数据默认是字符串处理
         * 传入参数的顺序为：url, data, call, [async]
         */
        $.put = function(){
            var len = arguments.length,
                    url = "",
                    data = {},
                    call = null,
                    async = true;
            console.log(len);
            if(len == 4){
                url = arguments[0];
                data = arguments[1];
                call = arguments[2];
                async = arguments[3];
            }else if(len == 3){
                url = arguments[0];
                data = arguments[1];
                call = arguments[2];
            }
            $.ajax({
                type: "PUT",
                url: url,
                data: data,
                success: call,
                async: async,
                dataType: "text"
            });
        };
    });


  /*  $(function(){
        var img = document.getElementById("img");
        var width = document.body.clientWidth;
        window.onmousemove = function(e){
            var x = e.clientX;
            img.style.left = -Math.ceil((x - width/2)/20) + "px";
        }
    }); */

    $(function(){
        $("#btn").on("click", function(){
            $.put("temp/json", {},function(data){
                console.log(data);
            });
        });
    });


</script>
</body>
</html>